function Select(){

	var factory = $("#factory"); 
	factory.empty(); 
	factory.append("<option value=''>选择厂别</option>");
	var fab =  $("#fab").val(); 
	if(fab=="CEL") factory.append("<option value='CEL'>CEL</option>");
	else if(fab=="ARY")	factory.append("<option value='ARY'>ARY</option>");
	else {
		factory.append("<option value='M1'>M1</option>");
		factory.append("<option value='M2'>M2</option>");
	}
	factory.val(fab);
	
	var classType = $("#classType"); 
	classType.empty(); 
	classType.append("<option value=''>选择班别</option>");
	classType.append("<option value='A'>A</option>");
	classType.append("<option value='B'>B</option>");
	classType.append("<option value='C'>C</option>");
	classType.append("<option value='W'>W</option>");
	
	//加载select框 start
	var type = $("#type"); type.empty(); type.append("<option value=''></option>");
	var ope_id = $("#ope_id"); ope_id.empty();
	var ope_id_Lcm = $("#ope_id_Lcm"); ope_id_Lcm.empty(); ope_id_Lcm.append("<option value='0' >选择站点</option>");
	var ope_id_add = $("#ope_id_add"); ope_id_add.empty(); ope_id_add.append("<option value='0' >选择站点</option>");
	var stype = $("#stype"); stype.empty(); stype.append("<option value='' ></option>");
	var sope_id = $("#sope_id"); sope_id.empty(); sope_id.append("<option value='' ></option>");
	
	var scope1 = $("#scope1").val(); 
	var auditType = $("#auditType"); auditType.empty(); auditType.append("<option value='' ></option>");
	var ope_id_LcmMDC = $("#ope_id_LcmMDC"); ope_id_LcmMDC.empty();
	var ope_id_ARY = $("#ope_id_ARY"); ope_id_ARY.empty(); ope_id_ARY.append("<option value='' >请选择站点</option>");
	var ope_id_Ary = $("#ope_id_Ary"); ope_id_Ary.empty();ope_id_Ary.append("<option value='0' >选择站点</option>");
	var selectscope = $("#scope"); //selectscope.empty(); 
	
	
	if(fab == "M1制造部"){
		selectscope.append("<option value='24'>M1制造部</option>");
	}else if(fab == "M2制造部"){
		selectscope.append("<option value='25'>M2制造部</option>");
	}else if(fab == "M1工程部"){
		selectscope.append("<option value='38'>M1工程部</option>");
	}else if(fab == "M2工程部"){
		selectscope.append("<option value='39'>M2工程部</option>");
	}
	
	var scope = $("#scope").val(); 
	
	var param = {};
	var codeurl = pms_url + "sys/code/list"; 
	$.ajax({  
        type : "post",  
        url : codeurl,  
        dataType: "json", 
        data : param, 
        async : false,  //同步
        success : function(data){ 
    		if(data.err_msg=="success"){
    			$.each(data.result, function(index, json) { 
//    					map[json.id]=json.name;
    					if(json.category == 1) {
    						type.append("<option value='"+json.id+"' >"+json.name+"</option>");
    						stype.append("<option value='"+json.id+"' >"+json.name+"</option>");
    					}
    					if(json.category == 5 && fab == "CEL") {
    						ope_id.append("<option value='"+json.id+"' >"+json.label+"</option>");
    						sope_id.append("<option value='"+json.id+"' >"+json.label+"</option>");
    					}	
    					if(json.category == 21) 
    						auditType.append("<option value='"+json.id+"' >"+json.name+"</option>");
    					
    					
    					if(json.category == 24 && (scope == 24 || scope1 == 24) ) {
    						ope_id_Lcm.append("<option value='"+json.id+"' >"+json.label+"</option>");
    						ope_id_add.append("<option value='"+json.id+"' >"+json.label+"</option>");
    					}	
    					if(json.category == 25 && (scope == 25 || scope1 == 25)) {
    						ope_id_Lcm.append("<option value='"+json.id+"' >"+json.label+"</option>");
    						ope_id_add.append("<option value='"+json.id+"' >"+json.label+"</option>");
    					}	
    					if(json.category == 38 && (scope == 38 || scope1 == 38) ) {
    						ope_id_Lcm.append("<option value='"+json.id+"' >"+json.label+"</option>");
    						ope_id_add.append("<option value='"+json.id+"' >"+json.label+"</option>");
    					}	
    					if(json.category == 39 && (scope == 39 || scope1 == 39)) {
    						ope_id_Lcm.append("<option value='"+json.id+"' >"+json.label+"</option>");
    						ope_id_add.append("<option value='"+json.id+"' >"+json.label+"</option>");
    					}	
    					if(json.category == 26 && (scope == 26 || scope == 27)) {
    						ope_id_LcmMDC.append("<option value='"+json.name+"' >"+json.name+"</option>");
    					}	
    					if((json.category == 28 || json.category == 29) && fab == "ARY") {
    						ope_id_Ary.append("<option value='"+json.id+"' >"+json.label+"</option>");
    						ope_id_ARY.append("<option value='"+json.id+"' >"+json.label+"</option>");
    						ope_id.append("<option value='"+json.id+"' >"+json.label+"</option>");
    						ope_id_add.append("<option value='"+json.id+"' >"+json.label+"</option>");
    					}	
    					if((json.category == 24 || json.category == 25 || json.category == 36 || json.category == 38 || json.category == 39) && (fab.search("M") != -1)) {
    						ope_id.append("<option value='"+json.id+"' >"+json.label+"</option>");
    					}	
    					
    					
    			});
    			if(fab == "LCM"){
    				$('#ope_id_Lcm').selectpicker('refresh');
    				$('#ope_id_add').selectpicker('refresh');
    			}
    		}
        	}
        });
	//加载select框 end
	
//		$("div").delegate(".form_date","focusin",function(){
//			$('.form_date').datetimepicker({
//				  language: 'zh-CN',/*加载日历语言包，可自定义*/
//				  pickerPosition: 'bottom-left',
//				  weekStart: 1,
//				  todayBtn: 1,
//				  autoclose: 1,
//				  todayHighlight: 1,
//				  startView: 2,
//				  minView: 2,
//				  forceParse: 0,
//				  format:"yyyy-mm-dd"
//			    });
//		});
	 
	

};
$(function(){
	var fab =  $("#fab").val(); 
	var selectscope = $("#scope");
	if(fab == "LCM"){
		selectscope.append("<option value='0'>ALL</option>");
		selectscope.append("<option value='24'>M1制造部</option>");
		selectscope.append("<option value='25'>M2制造部</option>");
		selectscope.append("<option value='38'>M1工程部</option>");
		selectscope.append("<option value='39'>M2工程部</option>");
	}
	Select();
	$("#scope").change(function(){
		Select();
	});
	$("#scope1").change(function(){
		Select();
	});
});
